package cn.egame.extraction.service;

import java.util.List;

import org.apache.log4j.Logger;

import cn.egame.common.exception.ExceptionCommonBase;
import cn.egame.extraction.dao.GameStatusDao;
import cn.egame.extraction.pojo.GameStatusInfo;
public class GameStatusService {
	private static GameStatusService instance = null;
	private static byte[] lock = new byte[0];
	private Logger log = Logger.getLogger(GameStatusService.class);

	public static GameStatusService getInstance() throws ExceptionCommonBase {
		if (instance == null) {
			synchronized (lock) {
				if (instance == null) {
					instance = new GameStatusService();
				}
			}
		}
		return instance;
	}

	private GameStatusDao dao = null;

	public GameStatusService() throws ExceptionCommonBase {
		dao = new GameStatusDao();
	}

	public void setGameStatus(GameStatusInfo gameStatus)  {
		int gId = gameStatus.getGId();
		if (gameStatus.getGId() <= 0) {
			return;
		}
		
		try {
			int dayCounts = ReportGameDayDownService.getInstance()
					.getReportGameDayDownCountByDay(gId);
			int totalCounts = ReportGameDayDownService.getInstance()
					.getReportGameDayDownCountIncrByDate(gId);
			int weekCounts = ReportGameDayDownService.getInstance()
					.getReportGameDayDownCountByWeek(gId);
//			int monthCounts = ReportGameDayDownService.getInstance()
//					.getReportGameDayDownCountByMonth(gId);
			gameStatus.setCountDownDay(dayCounts);
			gameStatus.setCountDownTotal(totalCounts);
			gameStatus.setCountDownWeek(weekCounts);
			gameStatus.setCountDownMonth(dayCounts);
			dao.setGameStatus(gameStatus);
		} catch (Exception e) {
			log.error(null,e);
		}

	}
	
	public List<GameStatusInfo> listGameStatus() throws ExceptionCommonBase {
		return dao.listGameStatus();
	}

	
	public int updateGameStatus(GameStatusInfo gameStatus) throws ExceptionCommonBase{
	    return dao.updateGameStatus(gameStatus);
	}
	
	
	public GameStatusInfo getGameStatus(int gId) throws ExceptionCommonBase {
		return dao.getGameStatus(gId);
	}
	

}
